package com.spring.boot.controller;

import com.spring.boot.MyDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

//Rest模式
@RestController
@RequestMapping("/books")
public class BookController {

    //读取yml数据中的单一数据
    @Value("${area}")
    private String area1;

    @Value("${user1.name}")
    private String user;

    @Value("${likes[2]}")
    private String likes;

    @Value("${users[1].name}")
    private String users;

    @Value("${tempDir}")
    private String tempDir;

    @Resource
    private MyDataSource myDataSource;

    // 使用自动装配将所有的数据封装到一个对象
    @Resource
    private Environment env;

    @GetMapping
    public String getById() {
        System.out.println(likes);
        System.out.println(user);
        System.out.println(area1);
        System.out.println(tempDir);
        System.out.println(users);
        System.out.println(" =============================================== ");
        System.out.println(env.getProperty("tempDir"));
        System.out.println(env.getProperty("users[1].name"));
        System.out.println(" =============================================== ");
        System.out.println(myDataSource);
        return "springboot is running 5";
    }

}
